<!--
 * @Author: your name
 * @Date: 2022-03-15 10:15:46
 * @LastEditTime: 2022-03-15 10:52:30
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \算法测试\day0906\Set.html
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        const set = new Set([2,2,3,4,5,5]);
        console.log(set);
        set.add(7);
        console.log(set);
        set.add(2);
        console.log(set);
        
        console.log(set);
        console.log(Array.from(set));
        console.log(set);
        
        console.log(set.delete(3));
        console.log(set.delete(10));

        console.log(set.has(2));
        console.log(set.has(8));

        console.log(set.clear());
        console.log(set.size);

        function dedupe(array) {//数组去重
            //return new Array(...new Set(array));
            return Array.from(new Set(array))
        }
        console.log(dedupe([7,7,8,9,0,1,2,2,2]));

        let set2 = new Set([8,9,0,1,23,45,123,435,123,3333,666])
        for(const item of set2.keys()){
            console.log(item);
        }
        for(const item of set2.values()){
            console.log(item);
        }
        for(const item of set2.entries()){
            console.log(item);
        }
        let a = new Set(Array.from(set2,val=>val*2))
        set2 = a;
        console.log(a);
    </script>
</body>
</html>